{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0af1f427",
   "metadata": {},
   "source": [
    "Python 运算符\n",
    "运算符用于对变量和值执行操作。\n",
    "\n",
    "在下面的示例中，我们使用 + 运算符将两个值相加："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "490b0f23",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n"
     ]
    }
   ],
   "source": [
    "print(10 + 5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "273a190d",
   "metadata": {},
   "source": [
    "Python 将运算符分为以下几组：\n",
    "\n",
    "算术运算符\n",
    "\n",
    "赋值运算符\n",
    "\n",
    "比较运算符\n",
    "\n",
    "逻辑运算符\n",
    "\n",
    "身份运算符\n",
    "\n",
    "成员运算符\n",
    "\n",
    "按位运算符\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93e1c9fa",
   "metadata": {},
   "source": [
    "# Python 算术运算符\n",
    "算术运算符与数值一起使用以执行常见的数学运算："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0aba3770",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "3\n",
      "10\n",
      "2.5\n",
      "1\n",
      "25\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "print(3+4)\n",
    "print(5-2)\n",
    "print(2*5)\n",
    "print(5/2)\n",
    "print(5%2)\n",
    "print(5**2)\n",
    "print(5//2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "364364f6",
   "metadata": {},
   "source": [
    "# Python 赋值运算符\n",
    "赋值运算符用于为变量赋值：\n",
    "<table>\n",
    "<tbody><tr>\n",
    "<th>Operator</th>\n",
    "<th>Example</th>\n",
    "<th>Same As</th>\n",
    "<th>Operator</th>\n",
    "<th>Example</th>\n",
    "<th>Same As</th>\n",
    "<th>Operator</th>\n",
    "<th>Example</th>\n",
    "<th>Same As</th>\n",
    "<th>Operator</th>\n",
    "<th>Example</th>\n",
    "<th>Same As</th>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>=</td>\n",
    "<td>x = 5</td>\n",
    "<td>x = 5</td>\n",
    "<td>+=</td>\n",
    "<td>x += 3</td>\n",
    "<td>x = x + 3</td>\n",
    "<td>-=</td>\n",
    "<td>x -= 3</td>\n",
    "<td>x = x - 3</td>\n",
    "<td>*=</td>\n",
    "<td>x *= 3</td>\n",
    "<td>x = x * 3</td>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>/=</td>\n",
    "<td>x /= 3</td>\n",
    "<td>x = x / 3</td>\n",
    "<td>%=</td>\n",
    "<td>x %= 3</td>\n",
    "<td>x = x % 3</td>\n",
    "<td>//=</td>\n",
    "<td>x //= 3</td>\n",
    "<td>x = x // 3</td>\n",
    "<td>**=</td>\n",
    "<td>x **= 3</td>\n",
    "<td>x = x ** 3</td>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>&amp;=</td>\n",
    "<td>x &amp;= 3</td>\n",
    "<td>x = x &amp; 3</td>\n",
    "<td>|=</td>\n",
    "<td>x |= 3</td>\n",
    "<td>x = x | 3</td>\n",
    "<td>^=</td>\n",
    "<td>x ^= 3</td>\n",
    "<td>x = x ^ 3</td>\n",
    "<td>&gt;&gt;=</td>\n",
    "<td>x &gt;&gt;= 3</td>\n",
    "<td>x = x &gt;&gt; 3</td>\n",
    "</tr>\n",
    "<tr>\n",
    "<td>&lt;&lt;=</td>\n",
    "<td>x &lt;&lt;= 3</td>\n",
    "<td>x = x &lt;&lt; 3</td>\n",
    "</tr>\n",
    "</tbody></table>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13db7acd",
   "metadata": {},
   "source": [
    "# Python 比较运算符\n",
    "比较运算符用于比较两个值："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "55d022e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(3==5)\n",
    "print(3!=5)\n",
    "print(3>5)\n",
    "print(3<5)\n",
    "print(3>=5)\n",
    "print(3<=5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "78b7445f",
   "metadata": {},
   "source": [
    "# Python 逻辑运算符\n",
    "逻辑运算符用于组合条件语句："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "700fdb63",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print(3<5 and 3<10)\n",
    "print(3<5 or 3<1)\n",
    "print(not(3<5 and 3<10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a00dfebe",
   "metadata": {},
   "source": [
    "# Python 身份运算符\n",
    "标识运算符用于比较对象，不是它们是否相等，而是它们是否实际上是同一个对象，具有相同的内存位置："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d2538a50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "x = y = \"qwer\"\n",
    "print(x is y)\n",
    "print(x is not y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3314970f",
   "metadata": {},
   "source": [
    "# Python 成员运算符\n",
    "成员运算符用于测试序列是否存在于对象中："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a74addda",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "x = 1\n",
    "y = [1,2,3]\n",
    "print(x in y)\n",
    "print(x not in y)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4e6f9fd",
   "metadata": {},
   "source": [
    "# Python 按位运算符\n",
    "按位运算符用于比较（二进制）数字："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb5893ce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
